package com.boyunv.iterator.example02;
/*
 *@description
 *  具体的迭代器
 *@author boyunv
 *@create 2023/9/1 7:18
 *@version 1.0
 */

public class TopicIterator implements IteratorIterator<Topic>{
    
    //topics数组
    private Topic[] topics;
    
    //记录存储位置的游标
    private  int position;
    
    public TopicIterator(Topic[] topics) {
        this.topics = topics;
        position=0;
    }
    
    @Override
    public void reset() {
        position=0;
    }
    
    @Override
    public Topic next() {
        return topics[position++];
    }
    
    @Override
    public Topic currentItem() {
        return topics[position];
    }
    
    @Override
    public boolean hasNext() {
        if (position>=topics.length){
            return false;
        }
        
        return true;
    }
}
